<template>
  <div class="additional-expense-page">
    <div class="search-wrapper">
      <super-search :search-form="searchForm" :search-item-config="searchItemList" @search="searchHandle"></super-search>
    </div>
    <div class="content-wrapper">
      <a-tabs v-model:activeKey="activeKey" @change="changeTabHandle">
        <a-tab-pane key="0" :tab="`未审核(${pageStat['0']})`"></a-tab-pane>
        <a-tab-pane key="1" :tab="`已审核(${pageStat['1']})`"></a-tab-pane>
      </a-tabs>
      <super-table
        :height="tableHeight"
        ref="tableRef"
        v-model:page="searchForm.pageNum"
        v-model:limit="searchForm.pageSize"
        :loading="loading"
        :activeKey="activeKey"
        :data="tableData"
        :total="searchForm.total"
        :column="tableColumn"
        @change-page="getData"
        :sort-config="{ remote: true }"
        @sort-change="sortChangeHandle"
      >
        <template #tool>
          <template v-if="activeKey === '0'">
            <a-button type="primary" @click="downloadDataHandle">批量导出</a-button>
            <a-button type="primary" @click="auditHandle" v-btnAuth="'ADDITIONALEXPENSE_AUDIT'">审核</a-button>
            <a-button type="primary" @click="addFeeHandle">追加费用</a-button>
            <a-button type="primary" @click="importAddFeeHandle">导入追加费用</a-button>
            <a-button type="danger" @click="deleteFeeHandle">删除</a-button>
          </template>
          <template v-if="activeKey === '1'">
            <a-button type="primary" @click="downloadDataHandle">批量导出</a-button>
            <a-button type="primary" @click="reverseFeeHandle" v-btnAuth="'ADDITIONALEXPENSE_REVERSEFEE'">反审核</a-button>
          </template>
          <a-button type="default" @click="showDeleteLogHandle">查看删除日志</a-button>
          <a-button type="primary" @click="showStatictisHandle">查看统计</a-button>
        </template>

        <template #action="{ row }">
          <a-button type="link" @click="modifyAddFeeHandle(row)" v-if="activeKey === '0'">修改费用</a-button>
        </template>
      </super-table>
    </div>
    <!-- 抽屉 -->
    <a-drawer class="custom-drawer" v-model:visible="drawerOpts.visible" :title="drawerOpts.title" :maskClosable="false" :closable="true" @close="getData" :width="drawerOpts.width" placement="right">
      <component v-model:visible="drawerOpts.visible" :is="drawerOpts.component" :type="drawerOpts.type" :pass-data="drawerOpts.passData" @submit="drawerSubmitHandle"></component>
    </a-drawer>
    <!-- 弹窗 -->
    <a-modal
      v-model:visible="dialogOpts.visible"
      :maskClosable="false"
      :keyboard="false"
      :closable="['DataStatistics'].includes(dialogOpts.component)"
      :footer="null"
      :title="dialogOpts.title"
      :width="dialogOpts.width"
    >
      <component
        v-model:visible="dialogOpts.visible"
        :column="statisticsColumn"
        :init="getStatisticsDataFn"
        :is="dialogOpts.component"
        :type="dialogOpts.type"
        :pass-data="dialogOpts.passData"
        @submit="dialogSubmitHandle"
      ></component>
    </a-modal>
  </div>
</template>
<script lang="ts">
import DataStatistics from "@/components/dataStatistics/index.vue";
import AddFee from "./components/addFee/index.vue";
import ImportAddFee from "./components/importAddFee/index.vue";
import DeleteLog from "./components/deleteLog/index.vue";
import TableHook from "@/hook/tableHook";
export default {
  name: "AdditionalExpense",
  components: {
    AddFee,
    ImportAddFee,
    DeleteLog,
    DataStatistics
  }
};
</script>
<script lang="ts" setup>
import TableHeightHook from "@/hook/tableHeightHook";
import ModalHook from "@/hook/modalHook";
import InitHook from "./composables/initHook";
import OperationHook from "./composables/operationHook";
import { searchItemList, statisticsColumn } from "./data";
import { onActivated } from "vue";
const { tableHeight, loading } = TableHeightHook(110);
const { tableData, searchForm, drawerOpts, tableRef, dialogOpts, activeKey, pageStat, tableColumn } = InitHook();
const {
  auditHandle,
  deleteFeeHandle,
  searchHandle,
  getData,
  importAddFeeHandle,
  changeTabHandle,
  addFeeHandle,
  reverseFeeHandle,
  showDeleteLogHandle,
  getStatisticsDataFn,
  showStatictisHandle,
  downloadDataHandle,
  modifyAddFeeHandle
} = OperationHook({
  searchForm,
  tableData,
  drawerOpts,
  loading,
  tableRef,
  dialogOpts,
  activeKey,
  pageStat
});
onActivated(() => {
  searchHandle();
});
const { sortChangeHandle } = TableHook({ searchForm }, getData);
const { drawerSubmitHandle, dialogSubmitHandle } = ModalHook({
  drawerOpts,
  dialogOpts,
  callBack: () => searchHandle()
});
</script>
<style lang="stylus" scoped></style>
